<template>
	<view class="info-wrap">
		<!-- <view class="info-heder"> -->
		<!-- <text>资产盘点</text> -->
		<!-- </view> -->
		<view>
			<view class="info-top" v-for="(item,index) in assetCountList" :key="index">
				<view class="vi">
					<view class="left">计划编号：</view>
					<view class="right"><text>{{item.plan.planNo}}</text></view>
				</view>
				<view class="vi">
					<view class="left">盘点目的：</view>
					<view class="right"><text>{{item.plan.checkAim}}</text></view>
				</view>
				<view class=" fload" :class="isFload ? 'hide' : 'show'">
					<view class="left">盘点区域：</view>
					<view class="right-t">
						<text>{{item.plan.regionIdText}}</text>
					</view>
					<!-- <image class="img imgg" src="../../static/image/xiala.png" mode="" v-if="isFload" @click="fload"></image>
					<image class="img imgg" src="../../static/image/xiala.png" mode="" v-if="!isFload" @click="fload"></image> -->
					<text class="img" v-if="isFload" @click="fload">  </text>
					<text class="img" v-if="!isFload" @click="fload">
						   </text>
				</view>
				<!-- <view class="vi">
					<image src="../../static/image/xiala.png" mode="" v-if="isFload" @click="fload"></image>
					<image src="../../static/image/xiala.png" mode="" v-if="!isFload" @click="fload"></image>
				</view> -->
				<view class="vi">
					<view class="left">{{typeText}}情况：</view>
					<view class="right"><text>{{item.plan.stateText}}</text></view>
				</view>
				<view class="vi">
					<view class="left">扫描{{typeText}}：</view>
					<view class="right"><text>{{item.plan.checkAim}}</text></view>
				</view>
				<view class="vi">
					<view class="left">开始时间：</view>
					<view class="right"><text>{{item.plan.checkStartTime}}</text></view>
				</view>
				<view class="vi">
					<view class="left">结束时间：</view>
					<view class="right"><text>{{item.plan.checkEndTime}}</text></view>
				</view>
				<view class="vi">
					<view class="left">设备总数：</view>
					<view class="right"><text>{{item.total}}</text></view>
				</view>
				<view class="vi">
					<view class="left">扫描设备：</view>
					<view class="right"><text>{{item.checkedCount}}</text></view>
				</view>
			</view>

			<view class="info-top">
				<view class="vi">
					<view class="left">设备：</view>
					<view class="right"></view>
				</view>
				<view class="" v-for="(item,index) in assetList" :key="index">
					<view class="vi">
						<view class="left">所属位置</view>
						<view class="right"><text>{{item.regionIdText}}</text></view>
					</view>
					<view class="vi">
						<view class="left">设备名称</view>
						<view class="right"><text>{{item.assetName}}</text></view>
					</view>
				</view>
			</view>
		</view>
		<!-- <button type="primary">提交</button> -->
		<button form-type="submit" :style="style2" class="sub_button" @click="cc()">扫一扫</button>
		<button form-type="submit" :style="style1" class="sub_button" @click="endAsset()">结束{{typeText}}</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isFload: true,
				style1: "display:none",
				style2:'',
				planId: '',
				assetCountList: [],
				assetList: [],
				assetNo: '',
				isRepeat: '',
				pushAssetName: '',
				pushRegionIdText: '',
				typeText: ''
			}
		},
		onLoad(option) {
			this.typeText = option.typeText
			this.planNo = option.planNo
			this.planId = option.planId
			let pageTitle = '资产' + this.typeText
			uni.setNavigationBarTitle({
			    title: pageTitle
			});
			this.getAssetDetails()
			this.qqq()
		},
		onBackPress(){
			let pages = getCurrentPages();
			let prevPage = pages[pages.length - 2];
			// prevPage.$vm.getRecordPlans()  //这个被注释起来了，在经过测试后确定不影响功能的时候再删掉
		},
		methods: {
			qqq() {
				console.log("11", this.assetCountList)
			},

			fload() {
				//改变isFload的状态
				this.isFload = !this.isFload;
			},


			async getAssetDetails() {
				const res = await this
					.$myRequest({ //await 关键字 只能放在 async 函数内部， await关键字的作用 就是获取 Promise中返回的内容， 获取的是Promise函数中resolve或者reject的值
						url: '/api-asset/recordPlans?planNo=' + this.planNo,
						method: "get",
					})
				console.log(res.msg)
				this.assetCountList = res.body.list
				console.log(this.assetCountList)
				this.uuu()
			},


			uuu() {
				var id = uni.getStorageSync('id')
				var name = uni.getStorageSync('loginName')
				console.log("id=" + id)
				console.log("name=" + name)
				console.log("checkLeader=" + this.assetCountList[0].plan.checkLeader)
				console.log("state=" + this.assetCountList[0].plan.state)
				if (this.assetCountList[0].plan.checkLeader == id) {
					this.style1 = ''
				}
				if (this.assetCountList[0].plan.state == '4') {
					this.style2 = 'display:none'
				}
			},

			cc(result) {
				// let data = this.assetList;
				// console.log(JSON.stringify(data))
				var _this = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log(res)
						if(res.result.match("zc")){
							res.result = "BCJK" + res.result.slice(2)
						}else if(res.result.match("BCJK")){
							res.result = res.result
						}else{
							res.result = "BCJK" + res.result
						}
						_this.assetNo = res.result
						console.log(res.result)
						console.log('条码类型3333：' + res.scanType);
						// console.log('条码内容4444：' + res.result);
						console.log("ttt+++"+_this.assetNo);
						_this.postScanCodeSave()
					}
				});
			},

			async endAsset() {
				// console.log("url阶段" + Astatus)
				const res = await this
					.$myRequest({ //await 关键字 只能放在 async 函数内部， await关键字的作用 就是获取 Promise中返回的内容， 获取的是Promise函数中resolve或者reject的值
						url: "/api-asset/checkPlans/finish",
						method: "post",
						data: {
							"planId": this.planId,
							"state": '4',
						}
					});
				uni.navigateBack({
					delta: 1,
				})
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 1];
				prevPage.$vm.getRecordPlans()
			},

			async postScanCodeSave() {
				console.log("=============================")
				let name = uni.getStorageSync('loginName')
				// console.log("url阶段" + Astatus)
				console.log(this.assetNo)
				console.log(this.planId)
				console.log(name)
				const res = await this
					.$myRequest({ //await 关键字 只能放在 async 函数内部， await关键字的作用 就是获取 Promise中返回的内容， 获取的是Promise函数中resolve或者reject的值
						url: "/api-asset/checkRecords/scan/save",
						method: "post",
						data: {
							"planId": this.planId,
							"assetNo": this.assetNo,
							"checkMan": name,
						}
					});
					console.log(res)
				if(res.code === "101"){
					uni.showToast({
						title: res.msg,
						icon:'none',
						duration: 700
					});
				}else{
					let isRepeat = res.data[0].isRepeat
					console.log(res)
					console.log(this.assetNo)
					console.log('啊飒飒的', isRepeat)
					if (isRepeat == false) {
						this.getAssetInfo()
						this.assetCountList[0].checkedCount++
					} else {
						uni.showToast({
							title: '重复扫描！',
							icon:'none',
							duration: 700
						});
						// console.log(isRepeat)
					}
				}
			},

			async getAssetInfo() {
				console.log("==================================")
				console.log(this.planId)
				console.log(this.assetNo)
				const res = await this
					.$myRequest({ //await 关键字 只能放在 async 函数内部， await关键字的作用 就是获取 Promise中返回的内容， 获取的是Promise函数中resolve或者reject的值
						url: '/api-asset/checkRecords/list?planId=' +
							this.planId + '&assetNo=' + this.assetNo,
						method: "get",
					});
				// console.log(res.msg)
				this.pushAssetName = res.body.list[0].assetName
				this.pushRegionIdText = res.body.list[0].regionIdText
				this.assetList.push({
					assetName: this.pushAssetName,
					regionIdText: this.pushRegionIdText,
				})
				console.log("assetList", this.assetList)
			},
		}
	}
</script>

<style>
	page {
		background-color: #ebeff6;
	}

	.info-heder {
		width: 100%;
		height: 120rpx;
		background-color: #109ef8;
		text-align: center;
	}

	.info-heder text {
		color: white;
		font-weight: 600;
		font-size: 38rpx;
		/* margin-left: 50rpx; */
		word-spacing: 100rpx;
	}

	.info-top {
		background-color: #FFFFFF;
		margin-bottom: 20rpx;
		font-size: 24rpx;
	}

	.vi {
		height: 80rpx;
		width: 100%;
		display: flex;
		border-bottom: 1rpx solid #ebebeb;
		align-items: center;
		/* border: 1rpx solid ; */
	}

	.img {
		display: flex;
		flex-direction: row-reverse;
		font-size: 32rpx;
		position: absolute;
		/* border: 1rpx solid #007AFF; */
		margin-top: -10.6%;
		/* margin-left: -3%; */
		width: 100%;
		height: 75rpx;
		color: #959595;
		border-bottom: 1rpx solid #ebebeb;
	}

	.fload {
		/* border: 1rpx solid; */
		line-height: 80rpx;
		/* border: 1rpx solid; */
		display: -webkit-box;
		word-break: break-all;
		-webkit-box-orient: vertical;
		/* 要显示多少行就改变line-clamp的数据,此处折叠起来显示一行*/
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.hide {
		display: -webkit-box;
	}

	.show {
		display: block;
	}

	.left {
		margin-left: 20rpx;
		width: 30%;
		color: #000000;
		font-size: 26rpx;
		/* font-weight: bold; */
	}

	.right-t {
		/* border: 1rpx solid; */
		margin-top: -11%;
		margin-left: 31%;
		width: 50%;
		color: #959595;
		font-size: 26rpx;
		/* font-weight: bold; */
		overflow: hidden;
		/* border-bottom: 1rpx solid #ebebeb; */
	}

	.yy {
		border-bottom: 1rpx solid #959595;
	}

	.right {
		width: 70%;
		color: #959595;
		font-size: 26rpx;
		/* font-weight: bold; */
		overflow: hidden;
	}

	.sub_button {
		height: 38px;
		width: 80%;
		background-color: #109EF8;
		color: #FFFFFF;
		line-height: 38px;
		text-align: center;
		margin: 28px auto 0 auto;
		border-radius: unset;
	}

	.info-wrap {
		align-items: center;
		justify-content: center;
	}
</style>
